package com.xhj.arithmetic;
import java.lang.reflect.Array;
import java.util.Arrays;
//import org.apache.commons.lang3.ArrayUtils;
/**
 * -
 *
 * @author 周沫
 * @Date 2021-07-19
 * @Time 18:45
 */
public class A0003 {

	public static void main(String[] args) {
		String str = "";
		System.out.println(str + ": " + new A0003().lengthOfLongestSubstring(str));
	}

	public int lengthOfLongestSubstring(String s) {
		class Util {

			boolean contains(char[] chars, char c) {
				for (int i = 0; i < chars.length; i++) {
					if (chars[i] == c)
						return true;
				}
				return false;
			}
		}
		int result = 1;
		char[] chars = s.toCharArray();
		if (!s.equals("")) {
			for (int i = 0; i < chars.length - 1; i++) {
				String str = String.valueOf(chars[i]);// - - - - - - -"i开头的子串"
				for (int j = i + 1; j < chars.length; j++) {
					if (!new Util().contains(str.toCharArray(), chars[j])) {
						str += chars[j];
						result = result > str.length() ? result : str.length();
					} else break;
				}
			}
			return result;
		} else return 0;
	}
	public int lengthOfLongestSubstring2(String s){
		int result=1;
		int winSize=1;
		if(!s.equals("")){
			for (int i = 0; i < s.toCharArray().length-winSize+1; i++) {
				while (!s.substring(i,i+winSize).contains(s.substring(i+winSize-1,i+winSize))){
					winSize++;
				}
					winSize=winSize>s.substring(i,i+winSize).length()?winSize:s.substring(i,i+winSize).length();

			}
		}else return 0;
		return result;
	}
}
